<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>AI颜值打分</title>
    <style>
		.bg{
            background-image: url('https://pic.nximg.cn/file/20191206/28968572_142702433936_1.jpg');
		    width: 113px; /*设置元素宽度*/
		    height: 150px; /*设置元素高度*/
		    margin: 0 auto; /*设置元素外边距*/
		    padding-top: 0px; /*设置元素上内边距*/
		}
		.shine{
		    width: 500px;
		    font-family: "Microsoft YaHei";
		    font-size: 10px;
		    text-align: center;
		    background: -webkit-linear-gradient(left, rgb(150, 0, 0), rgb(255, 153, 0)) 0 0 no-repeat;/*设置线性渐变*/
		    -webkit-background-size: 500px;                        /*设置背景大小*/
		    -webkit-background-clip: text;                            /*背景被裁剪到文字*/
		    -webkit-text-fill-color: rgba(255, 255, 255, 0.3);        /*设置文字的填充颜色*/
            position: absolute;
            top: 40%;
            left: 50%;
            transform: translate(-50%, -200%);
        }
		
	</style>
    <style>
        h1 {
            font-family: 'Indie Flower', cursive;
            text-align: center;
        }
        .center {
            text-align: center;
        }
        #captureButton {
            margin: 0 auto;
            position: relative; /* 或者使用 absolute */
            top: -70px;
            display: inline-block; /* 修改为内联块元素 */
            padding: 10px 20px;
            background-color: #4CAF50; /* 添加背景颜色 */
            color: white; /* 设置文字颜色 */
            border: none; /* 移除边框 */
            border-radius: 5px; /* 添加圆角 */
            box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2); /* 添加阴影 */
            cursor: pointer;
            transition: background-color 0.3s ease; /* 添加过渡效果 */
        }
        #captureButton:hover {
            background-color: #45a049; /* 悬停时的背景颜色 */
        }
    </style>
</head>
<body>
    <div class="bg">
    <h1 align="center" class="shine">AI颜值打分<br> 
        免费用户一日可试用1次<br>
        购买此会员（19.9＄/月）<br>
        限时折扣
    </h1>
    </div>
    <div style="text-align: center;"> <!-- 使用一个容器来将按钮置于中央 -->
        <div class="center">
        <button id="captureButton" style="margin: 0 auto; display: block; padding: 10px 20px;">上传或拍照</button>
    </div>
    <canvas id="canvas" style="display:none;"></canvas>
    <script>
        document.getElementById('captureButton').addEventListener('click', function() {
            var canvas = document.getElementById('canvas');
            var context = canvas.getContext('2d');

            // 访问用户摄像头
            navigator.mediaDevices.getUserMedia({ video: true })
                .then(function(stream) {
                    // 在 Canvas 上显示摄像头捕获的视频流
                    var video = document.createElement('video');
                    video.srcObject = stream;
                    video.play();
                    video.addEventListener('loadedmetadata', function() {
                        canvas.width = video.videoWidth;
                        canvas.height = video.videoHeight;
                        context.drawImage(video, 0, 0, canvas.width, canvas.height);
                        
                        // 将 Canvas 中的图像转换为 data URL
                        var imageDataURL = canvas.toDataURL('image/jpeg');

                        // 停止视频流
                        stream.getTracks().forEach(function(track) {
                            track.stop();
                        });

                        /*// 发送图像数据到服务器
                        var xhr = new XMLHttpRequest();
                        xhr.open('POST', '/upload', true);
                        xhr.setRequestHeader('Content-Type', 'application/json');
                        xhr.onload = function() {
                            if (xhr.status === 200) {
                                alert('上传成功!');
                            } else {
                                alert('上传失败!');
                            }
                        };*/
                        // 将图像保存到本地
                        var link = document.createElement('a');
                        link.download = 'snapshot.jpg';
                        link.href = imageDataURL;
                        link.click();
                        xhr.send(JSON.stringify({ image: imageDataURL }));
                    });
                })
                .catch(function(error) {
                    console.error('摄像头访问失败:', error);
                });
        });
    </script>
</body>
</html>

